package view
{
	import alternativa.engine3d.core.Object3D;
	import alternativa.engine3d.events.MouseEvent3D;
	import alternativa.engine3d.materials.DevMaterial;
	import alternativa.engine3d.materials.FillMaterial;
	import alternativa.utils.MathUtils;
	
	import com.adobe.cairngorm.control.CairngormEvent;

	public class MiniCube extends Object3D
	{
		private var _front:MiniCubeFace;
		private var _back:MiniCubeFace;
		private var _top:MiniCubeFace;
		private var _bottom:MiniCubeFace;
		private var _left:MiniCubeFace;
		private var _right:MiniCubeFace;
		
		public var id:int;
		
		public function MiniCube(name:String=null)
		{
			super(name);
			init();
		}
		
		private function init():void
		{
			_front = new MiniCubeFace("front", new DevMaterial(0,0xFF0000));
			_back = new MiniCubeFace("back",new DevMaterial(0,0x00FF00));
			_top = new MiniCubeFace("top",new DevMaterial(0,0x0000FF));
			_bottom = new MiniCubeFace("bottom",new DevMaterial(0,0xFF00FF));
			_left = new MiniCubeFace("left",new DevMaterial(0,0x00FFFF));
			_right = new MiniCubeFace("right",new DevMaterial(0,0xFFFFFF));
			
			this.addChild(_front);
			this.addChild(_back);
			this.addChild(_top);
			this.addChild(_bottom);
			this.addChild(_left);
			this.addChild(_right);
			
			var deg90:Number = MathUtils.DEG90;
			
			_front.rotationX = deg90;
			_front.y = -5;
			_back.rotationX = deg90;
			_back.y = 5;
			
			_top.z = 5;
			_bottom.z = -5;
			
			_left.rotationY = deg90;
			_left.x = -5;
			_right.rotationY = deg90;
			_right.x = 5;
			
			this.addEventListener(MouseEvent3D.MOUSE_OUT, onOut);
			_front.addEventListener(MouseEvent3D.MOUSE_OVER, onOver);
			_back.addEventListener(MouseEvent3D.MOUSE_OVER, onOver);
			_top.addEventListener(MouseEvent3D.MOUSE_OVER, onOver);
			_bottom.addEventListener(MouseEvent3D.MOUSE_OVER, onOver);
			_left.addEventListener(MouseEvent3D.MOUSE_OVER, onOver);
			_right.addEventListener(MouseEvent3D.MOUSE_OVER, onOver);
			//onOut(null); 
		}
		
		private function onOut(e:MouseEvent3D):void
		{
			_front.alpha = 1;
			_back.alpha = 1;
			_top.alpha = 1;
			_bottom.alpha = 1;
			_right.alpha = 1;
			_left.alpha = 1;
		}
		
		private function onOver(e:MouseEvent3D):void
		{
			
			onOut(e);
			e.currentTarget.alpha = 0.9;
			var event:CairngormEvent = new CairngormEvent("console");
			//Alert.show(e.currentTarget.mesh.transformation.getRotations())ss

			
			var object:Object = { cube:this, face:e.currentTarget };
			event.data = object;
			event.dispatch();	
		}
		
	}
}